package com.beetlestech.nfe.main.biz.com.impl;

import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.main.biz.com.HbPhoneRegister;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.tbl.MststudentDTO;
import com.beetlestech.nfe.main.db.tbl.MstusrDTO;

public class HbPhoneRegisterImpl extends AbstractDBLogic implements HbPhoneRegister, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant{

	@Override
	public void insertUserInfo(String phone, String userName, String passWord) {
		checkUserInfo(phone,userName);
		MstusrDTO mstusrDTO =new MstusrDTO(); 
		mstusrDTO.setphone(phone);
		mstusrDTO.setusername(userName);
		mstusrDTO.setpassword(passWord);
		mstusrDTO.settype(0);
		mstusrDTO.setstate(1);
		mstusrDTO.setfirstloginflg(0);
		mstusrDTO.setlastdate(getCurrentDate());
		mstusrDTO.setlasttime(getCurrentTime());
		updateDAO.updateOne(MstusrDTO.INSERT,mstusrDTO,M10040WS);
		MststudentDTO mststudentDTO=new MststudentDTO();
	    mststudentDTO.setusrid(mstusrDTO.getusrid());
	    mststudentDTO.setlastdate(getCurrentDate());
	    mststudentDTO.setlasttime(getCurrentTime());
	    updateDAO.updateOne(MststudentDTO.INSERT,mststudentDTO,M10040WS);
	}
	private void checkUserInfo(String phone, String userName) {
		MstusrDTO mstusrDTO =new MstusrDTO(); 
		mstusrDTO.setphone(phone);
		//mstusrDTO.setusername(userName);
		if(queryDAO.count(MstusrDTO.COUNT, mstusrDTO) > 0){
			createApplicationException(M10050WC);
		}else{
			mstusrDTO.setphone(null);
			mstusrDTO.setusername(userName);
			if(queryDAO.count(MstusrDTO.COUNT, mstusrDTO) > 0){
				createApplicationException(M10070WC);
			}
		}
	}
}
